-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for private fields in @BeanParam
#5525
Adding support for private fields in @BeanParam
#5525
Conversation
Signed-off-by: Divyansh Shekhar Gaur <[email protected]>
Signed-off-by: Divyansh Shekhar Gaur <[email protected]>
Signed-off-by: Divyansh Shekhar Gaur <[email protected]>
A universal solution would likely be to set the |
@jansupol I thought of that as well. However, if we do that, then if someone has defined the annotations on both the field and the getter, then the annotations on the getter would not be detected as it wouldn't go into Let me know your thoughts on this. |
You want to override the field value by the getter. But it is inconsistent, the getter overrides the value only for the private fields, and not for the public ones. |
I think if the POJO classes are written as per convention, there should either be public fields or getters but not both. In that case this would work as expected. |
Hi @divyanshshekhar, just FYI,
Here is a part of the stack trace for reference:
|
@ivan-slavchev Would you care to create a patch? |
@jansupol here is a patch, I hope it helps: |
Purpose
Added support for private fields in POJOs used as
BeanParam
Issue / Need
The jersey server already supports classes with private fields annotated QueryParam, HeaderParam etc to be used as BeanParam in the JAX-RS API interface. e.g.
Given a POJO representing an employee:
We can use the above class as
@BeanParam
in our service interface as belowThe above works with Jersey server.
However, the same class and interface cannot be used with
jersey-proxy-client
as of now because thejersey-proxy-client
, upon encountering fields with private fields having getters failes with following error:This breaks the compatibility of having a common API module with JAX-RS annotated service interfaces and POJOs shared by the server application and the various client applications which might be using the same service. This is a typical usecase.
Why it fails
It is not checking if the field is accessible before calling
Field.get(beanParam)
, which causes the above error. This statement is reached when a class being used as@BeanParam
has annotations on the field declaration but the field is private.Fix
Check if the field is accessible in the current beanParam object before calling get(). If the field is accessible, get the value, otherwise use the getter for that field if present.
Affected Versions:
3.x
4.x
Fixed #5526
Signed-off-by: Divyansh Shekhar Gaur [email protected]